package com.bawei.mall.cart.domain;


import com.bawei.common.core.annotation.Excel;
import com.bawei.common.core.web.domain.BaseEntity;
import com.bawei.mall.cart.domain.cache.CartCacheKey;
import com.bawei.mall.cart.domain.cache.CartCacheModel;
import com.bawei.mall.product.domain.MallProductSkuInfo;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.math.BigDecimal;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class CartInfo extends BaseEntity {

    private static final long serialVersionUID = 1L;

    /**
     * 主键
     */
    private Long id;


    @Excel(name = "商品Id")
    private Long productId;


    @Excel(name = "商品规格")
    private String productSku;


    @Excel(name = "数量")
    private Long sum;


    @Excel(name = "购物车价格")
    private BigDecimal cartPrice;


    public static  CartInfo productSkuBuild(MallProductSkuInfo mallProductSkuInfo,Long number){
        return CartInfo.builder()
                .productId(mallProductSkuInfo.getProductId())
                .productSku(mallProductSkuInfo.getSku())
                .cartPrice(mallProductSkuInfo.getPrice())
                .sum(number)
                .build();
    }

    public  static  CartInfo cartCacheBuild(CartCacheKey cartCacheKey, CartCacheModel cartCacheModel){
        return CartInfo.builder()
                .sum(cartCacheModel.getSum())
                .productId(cartCacheKey.getProductId())
                .productSku(cartCacheKey.getProductSku())
                .build();
    }

}
